//
//  SWOrderDetailFetchReq.swift
//  ChildStory
//
//  Created by linhan on 2017/1/19.
//  Copyright © 2017年 Aiya. All rights reserved.
//

import Foundation
class SWOrderDetailFetchReq: SWBaseRequest
{
    var orderID:String = ""
    
    override init()
    {
        super.init()
        api = SWRequestAPI.AddressCreate
    }
    
    override var url:String
    {
        return "http://mpic.bbyiya.com/order/getOrderInfo"
    }
    
    override var params:Any?
    {
        return ["orderId":orderID]
    }
    
    override func JSONToModel(_ json:JSON, JSONString:String, JSONData:Data) -> AnyObject?
    {
        //trace(json)
        return Mapper<SWOrderDetailFetchRsp>().map(JSONString: JSONString)
    }
}

class SWOrderDetailFetchRsp: NSObject,Mappable
{
    var statu:String?
    var order:SWOrderRsp?
    
    
    required init?(map: Map) { }
    
    // Mappable
    func mapping(map: Map) {
        statu             <- map["Statu"]
        order             <- map["BaseModle"]
    }
}

class SWOrderRsp: NSObject,Mappable
{
    var orderID:String?
    var price:Double?
    var status:Int?
    var remark:String?
    var addressee:SWOrderAddresseeInfoRsp?
    var creationDate:Date?
    var products:[SWOrderProductRsp]?
    
    required init?(map: Map) { }
    
    // Mappable
    func mapping(map: Map) {
        let formatter:DateFormatter = DateFormatter()
        formatter.dateFormat = "YYYY-MM-dd"
        
        orderID                   <- map["userOrderId"]
        price                     <- map["totalprice"]
        status                    <- map["status"]
        remark                    <- map["remark"]
        addressee                 <- map["orderAddress"]
        products                  <- map["prolist"]
        creationDate              <- (map["orderTimeStr"], DateFormatterTransform(dateFormatter: formatter))
    }
}

class SWOrderAddresseeInfoRsp: NSObject,Mappable
{
    var id:Int?
    var receiver:String?
    var provinceName:String?
    var cityName:String?
    var districtName:String?
    var phone:String?
    var postcode:String?
    var block:String?
    
    
    required init?(map: Map) { }
    
    // Mappable
    func mapping(map: Map) {
        id                      <- map["orderaddressid"]
        receiver                <- map["reciver"]
        provinceName            <- map["province"]
        cityName                <- map["city"]
        districtName            <- map["district"]
        phone                   <- map["phone"]
        postcode                <- map["postcode"]
        block                   <- map["streetdetail"]
    }
}

class SWOrderProductRsp: NSObject,Mappable
{
    var id:String?
    var count:Int?
    var price:Double?
    var title:String?
    
    
    required init?(map: Map) { }
    
    // Mappable
    func mapping(map: Map) {
        id                      <- map["productid"]
        count                   <- map["count"]
        price                   <- map["price"]
        title                   <- map["producttitle"]
    }
}

